package ltg.ibutton.aquaroom;

import java.sql.Timestamp;
import java.util.ArrayList;

import ltg.ibutton.core.Concept;

public class WaterSample extends Concept implements HavingColor {
	private float x,y;
	private String bid, station, info;
	private Timestamp timestamp;
	
	public WaterSample() {}
	
	public WaterSample(String bid, Timestamp t, float x, float y, String station, String info) {
		this.bid = bid;
		this.timestamp = t;
		this.x = x;
		this.y = y;
		this.station = station;
		this.info = info;
	}
	
	public WaterSample(String bid, String station) {
		this.bid = bid;
		this.station = station;
		this.x = -1;
		this.y = -1;
		this.info = "";
	}
	
	
	public String toString() {
		return"[WaterSample "+this.bid+"]: "+this.timestamp+" @("+this.x+", "+this.y+"), from station "+this.station+", info: "+this.info;
	}
	
	public String getBid() { return this.bid; }
	public Timestamp getTimestamp() { return this.timestamp; }
	public float getX() { return this.x; }
	public float getY() { return this.y; }
	public void setX(float x) { this.x = x; }
	public void setY(float y) { this.y = y; }
	public void setTimestamp(Timestamp t) { this.timestamp = t; }
	public String getStationId() { return this.station; }
	public String getInfo() { return this.info; }

	@Override
	public ArrayList<ColorBand> getColors() {
		ArrayList<ColorBand> c = new ArrayList<ColorBand>();
		if(AquaRoomPersistence.isAnewTube(this.getBid()) || this.info.equals("NO WATER")) { 
			//a never used tube will have a flat graph
			c.add(null);
		}
		else {
			if(!this.info.equals("")) {
				String[] tmp = this.info.split("&");
				for(int i=0; i<tmp.length; i++) {
					String[] kv = tmp[i].split("=");
					c.add(new ColorBand(kv[0], Double.parseDouble(kv[1])));
				}
			}
		}
		return c;
	}

}
